package com.backend.securitiessystem.service.impl;

import com.backend.securitiessystem.dao.ICapitalFlowDao;
import com.backend.securitiessystem.dto.CapitalFlowDto;
import com.backend.securitiessystem.pojo.CapitalFlow;
import com.backend.securitiessystem.service.CapitalFlowService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * 资本流动服务隐含
 *
 * @author LWY
 * @date 2024-05-23 03:38:04
 */
@Service
public class CapitalFlowServiceImpl extends ServiceImpl<ICapitalFlowDao, CapitalFlow> implements CapitalFlowService {

    @Override
    public IPage<CapitalFlowDto> selectPageWithCondition(int current, int size,
                                                         QueryWrapper<CapitalFlow> queryWrapper) {
        Page<CapitalFlow> page1 = new Page<>(current, size);
        IPage<CapitalFlow> capitalFlowIPage = this.page(page1, queryWrapper);

        List<CapitalFlowDto> capitalFlowDtoList = new ArrayList<>();
        for (CapitalFlow capitalFlow : capitalFlowIPage.getRecords()) {
            CapitalFlowDto capitalFlowDto = new CapitalFlowDto();
            capitalFlowDto.setFlow(capitalFlow.getFlow());
            capitalFlowDto.setFlowName(capitalFlow.getFlowName());
            capitalFlowDto.setLimits(capitalFlow.getLimits());
            capitalFlowDto.setBalance(capitalFlow.getBalance());
            capitalFlowDtoList.add(capitalFlowDto);
        }

        IPage<CapitalFlowDto> capitalFlowDtoIPage = new Page<>();
        capitalFlowDtoIPage.setSize(size);
        capitalFlowDtoIPage.setCurrent(current);
        capitalFlowDtoIPage.setRecords(capitalFlowDtoList);
        capitalFlowDtoIPage.setTotal(capitalFlowIPage.getTotal());
        return capitalFlowDtoIPage;
    }
}
